// pages/addAdress/addAdress.js
var common = require("../../utils/util.js");
Page({

    /**
     * 页面的初始数据
     */
    data: {
        name:'',
        mobile:'',
        address:'',
        province:'',
        city:'',
        county:'',
        id:'',
        defaultStatus:''
    },
    changeDefault: function () {
        if(this.data.defaultStatus == '是'){
            this.setData({
                defaultStatus: ''
            })
        }else{
            this.setData({
                defaultStatus: '是'
            })
        }
    },
    nameInput: function (e) {
        this.setData({
            name: e.detail.value
        })
    },
    mobileInput: function (e) {
        this.setData({
            mobile: e.detail.value
        })
    },
    addressInput: function (e) {
        this.setData({
            address: e.detail.value
        })
    },
    submit: function () {
        if(this.data.name == ''){
            common.info('请输入姓名')
            return false
        }
        if(this.data.mobile == ''){
            common.info('请输入手机号码')
            return false
        }
        if(!common.is_mobile(this.data.mobile)){
            common.info('手机号码格式错误')
            return false
        }
        if(this.data.address == ''){
            common.info('请输入详细地址')
            return false
        }
        common.set_userinfo({access_token:'5bba6e733f6530a7985eb5a77493353b'})
        var that = this;
        common.ajax({
            url: 'User/editUserAddress',
            data: {
                name: that.data.name,
                mobile: that.data.mobile,
                province: that.data.province,
                city: that.data.city,
                county: that.data.county,
                address: that.data.address,
                ua_id : that.data.id,
                default: that.data.default
            },
            loading: '加载中...',
            userinfo: true,
            success: function (res) {
                if (res.status == 'SUCCESS') {
                    console.log(JSON.stringify(res))
                } else {
                    common.info(res.result.msg)
                }
            }
        })
    },
    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function (options) {
        wx.setNavigationBarTitle({
            title: '添加地址'
        });
    },

    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady: function () {

    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow: function () {

    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide: function () {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload: function () {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh: function () {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom: function () {

    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage: function () {

    }
})